import React, { Component } from "react";
import Child1 from "./Child1";
import Child2 from "./Child2";

class App extends Component {
  constructor() {
    super();
    this.state = {
      count: 0,
    };
  }

  fn(num) {
    console.log(num);
    this.setState({
      count: num,
    });
  }

  render() {
    return (
      <>
        <h3>状态提升 - {this.state.count}</h3>
        {/* 子传父依旧是使用自定义事件 */}
        <Child1 onGetCount={this.fn.bind(this)} />
        {/* 父传子使用的还是自定义属性 */}
        <Child2 count={this.state.count} />
      </>
    );
  }
}

export default App;
